home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Games / Pentominoes 2.0 / Pent code / pent.c < prev    next >
Text File  |  1995-07-29  |  4KB  |  116 lines

  1. Shapes[i][j][k]=0;
  2.     gShapes[0][0][0]=gShapes[0][1][0]=gShapes[0][2][0]=gShapes[0][3][0]=gShapes[0][4][0]=1;
  3.     gShapes[1][0][0]=gShapes[1][1][0]=gShapes[1][2][0]=gShapes[1][3][0]=gShapes[1][3][1]=1;
  4.     gShapes[2][0][0]=gShapes[2][1][0]=gShapes[2][2][0]=gShapes[2][2][1]=gShapes[2][2][2]=1;
  5.     gShapes[3][0][1]=gShapes[3][1][0]=gShapes[3][1][1]=gShapes[3][1][2]=gShapes[3][2][1]=1;
  6.     gShapes[4][0][0]=gShapes[4][0][1]=gShapes[4][1][0]=gShapes[4][1][1]=gShapes[4][1][2]=1;
  7.     gShapes[5][0][0]=gShapes[5][1][0]=gShapes[5][1][1]=gShapes[5][2][1]=gShapes[5][2][2]=1;
  8.     gShapes[6][0][0]=gShapes[6][0][2]=gShapes[6][1][0]=gShapes[6][1][1]=gShapes[6][1][2]=1;
  9.     gShapes[7][0][1]=gShapes[7][0][2]=gShapes[7][1][1]=gShapes[7][2][0]=gShapes[7][2][1]=1;
  10.     gShapes[8][0][0]=gShapes[8][1][0]=gShapes[8][2][0]=gShapes[8][2][1]=gShapes[8][3][0]=1;
  11.     gShapes[9][0][1]=gShapes[9][1][0]=gShapes[9][1][1]=gShapes[9][2][1]=gShapes[9][2][2]=1;
  12.     gShapes[10][0][0]=gShapes[10][0][1]=gShapes[10][0][2]=gShapes[10][1][1]=gShapes[10][2][1]=1;
  13.     gShapes[11][0][0]=gShapes[11][1][0]=gShapes[11][2][0]=gShapes[11][2][1]=gShapes[11][3][1]=1;
  14.  
  15.     if (gHasColorQD)
  16.     {
  17.         for (i=0; i<kNumColors; i++)
  18.         {
  19.             percent=gColorPercent[i];
  20.             percent/=100;
  21.             color=65535*percent;
  22.             gColor[i].red=gColor[i].green=gColor[i].blue=color;
  23.         }
  24.         
  25.         for (i=0; i<kNumTilesPatterns; i++)
  26.         {
  27.             gTilePattern[i]=GetPixPat(128+i);
  28.         }
  29.         
  30.         gTileColor[kLeftEdge]=gColor[kLightGray];
  31.         gTileColor[kBottomEdge]=gColor[kVeryMediumGray];
  32.         gTileColor[kFace]=gColor[kMediumGray];
  33.         gTileColor[kRidgeDark]=gColor[kBlack];
  34.         gTileColor[kRidgeLight]=gColor[kWhite];
  35.         gTileColor[kRidge]=gColor[kMediumGray];
  36.     }
  37. }
  38.  
  39. void NewGame(void)
  40. {
  41.     WindowRef        theWindow;
  42.     
  43.     if ((theWindow=GetIndWindowRef(kMainWindow))!=0L)
  44.     {    /* may happen if gAskBeforeClosing is FALSE */
  45.         SetWindowIsModified(theWindow, FALSE);
  46.         CloseTheWindow(theWindow);
  47.     }
  48.     
  49.     if (InitGameVariables())
  50.     {
  51.         OpenTheIndWindow(kMainWindow, kAlwaysOpenNew);
  52.         StartGame();
  53.     }
  54. }
  55.  
  56. Boolean InitGameVariables(void)
  57. /* returns TRUE if successful, FALSE if error */
  58. {
  59.     OSErr            oe;
  60.     short            oldRefNum, refNum, i, j;
  61.     Boolean            alreadyOpen;
  62.     Handle            resHandle;
  63.     MyBoardRec        boardRec;
  64.     
  65.     if ((oe=OpenTheResFile(GetBoardsFileFSPtr(), &oldRefNum, &refNum, &alreadyOpen, TRUE))!=noErr)
  66.     {
  67.         HandleError(kCantLoadBoard, FALSE, FALSE);
  68.         return FALSE;
  69.     }
  70.     
  71.     resHandle=Get1NamedResource(kBoardResType, gCurrentGroupName);
  72.     if (resHandle!=0L)
  73.     {
  74.         Mymemcpy((Ptr)&boardRec, (Ptr)((unsigned long)*resHandle+sizeof(MyBoardRec)*gCurrentBoardIndex),
  75.             sizeof(MyBoardRec));
  76.         ReleaseResource(resHandle);
  77.         
  78.         gNumRows=boardRec.numRows;
  79.         gNumCols=boardRec.numColumns;
  80.         SetNewMainWindowTitle(boardRec.title);
  81.         for (i=0; i<kBoardRowsMax; i++)
  82.             for (j=0; j<kBoardColumnsMax; j++)
  83.                 gBoard[i][j]=boardRec.boardData[i][j];
  84.         for (i=0; i<12; i++)
  85.             gPieceUsed[i]=FALSE;
  86.         gNumHilited=0;
  87.         gNumPlayed=0;
  88.         gSelectedPieceColor=kSelectedTile;
  89.         gThisGameTileSize=gTileSize;
  90.     }
  91.     else HandleError(kCantLoadBoard, FALSE, FALSE);
  92.     
  93.     CloseTheResFile(oldRefNum, refNum, alreadyOpen);
  94.     
  95.     return TRUE;
  96. }
  97.  
  98. void StartGame(void)
  99. {
  100.     WindowRef        theWindow;
  101.     
  102.     if ((theWindow=GetIndWindowRef(kMainWindow))==0L)
  103.     {
  104.         SetCursor(&qd.arrow);
  105.         HandleError(kNoMemory, FALSE, FALSE);
  106.     }
  107.     else
  108.     {
  109.         MySelectWindow(theWindow);
  110.         SetWindowIsModified(theWindow, FALSE);
  111.         UpdateTheWindow(theWindow);
  112.         DoSound(sound_startgame, TRUE);
  113.     }
  114.     gCustomCursor=FALSE;
  115. }
  116.